package com.example.demo.service;

import com.example.demo.mapper.UserInfoMapper;
import com.example.demo.model.UserInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserService {
    @Resource
    private UserInfoMapper userInfoMapper;

    // 表示不管 UserController 中的add3方法是否存在事务，该add方法也会重新新建事务，所以日志添加出现异常不会回滚这里添加用户的操作
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int add(UserInfo userInfo){
        return userInfoMapper.add(userInfo);
    }
}
